package com.itheima.core.service.message;

import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;

import org.apache.activemq.command.ActiveMQTextMessage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.itheima.core.service.SearchService;
import com.itheima.core.service.SearchServiceImpl;

/**
 * 自定义的处理类
 * 
 * @author lx
 *
 */
public class CustomMessageListense implements MessageListener {

	private static Logger logger = LoggerFactory.getLogger(SearchServiceImpl.class); 

	@Autowired
	private SearchService searchService;

	@Override
	public void onMessage(Message message) {
		ActiveMQTextMessage amt = (ActiveMQTextMessage) message;
		try {
			String id = amt.getText();
			System.out.println("activemq接收商品id为：" + id + "的商品开始上架到solr索引库");
			logger.info("activemq接收商品id为：" + id + "的商品开始上架到solr索引库");
			searchService.insertProductToSolr(Long.parseLong(id));
		} catch (JMSException e) {
			e.printStackTrace();
		}
	}

}
